<?php

    if ( !defined ( 'BASEPATH' ) )
        exit ( 'No direct script access allowed' );

    if ( !function_exists ( 'compareItems' ) )
    {

        /**
         * Comparison function
         * 
         * @param   $a: stdclass, $b: stdclass
         * 
         * @return  0, -1, 1
         */
        function compareItems ( $a, $b )
        {
            if ( $a->cnt == $b->cnt )
                return 0;

            return ($a->cnt > $b->cnt) ? -1 : 1;
        }

    }

    if ( !function_exists ( 'sort_attributes' ) )
    {

        function sort_attributes ( &$unique )
        {
            // procedural:
            uasort ( $unique, 'compareItems' );


            // procedural:
            //uasort ( $collection, 'my_sort_function' );
            // Object Oriented
            //uasort ( $collection, array ($this, 'mySortMethod') );
            // Objet Oriented with static method
            //uasort ( $collection, array ('self', 'myStaticSortMethod') );
        }

    }
?>
